home *** CD-ROM | disk | FTP | other *** search
/ Teach Your Children: Road Construction Ahead / Teach Your Children: Road Construction Ahead.iso / pc / rca / road.dxr / 00006_MenuData Parent.ls < prev    next >
Encoding:
Text File  |  1996-07-17  |  11.6 KB  |  374 lines

  1. property firstChannel, sectionList, currentSection, dataString, saveEnabled, printEnabled, quitEnabled, savedGameList, nonEmptyGames, trailsSprite, loadGamePopChan, quitButChan, firstNameChan, nameX, nameY, awardsList, quitFlag, quitButObj, helpList
  2. global gLevelObject, gUserObject, gSceneObject, gSimObject, gGasGaugeObject, gMenuObject, gTruckObject, gVTLgameObject, gVTLobject, gSavePath, gInitObject, gAwardsObject, gHardHatObject, gActorList, gAlbumObject, gLoopGroupObject, gCDpath, gFileSep
  3.  
  4. on birth me
  5.   set trailsSprite to 15
  6.   set currentSection to 0
  7.   set sectionList to ["3dSite", "Simulator", "MakeAscene", "VTL", "HardHat", "Album", "Awards"]
  8.   set firstChannel to 1
  9.   set firstNameChan to 26
  10.   set nameX to 197
  11.   set nameY to 60
  12.   set quitButChan to 11
  13.   set popupChan to 10
  14.   set loadGamePopChan to 21
  15.   set dataString to EMPTY
  16.   set awardsList to []
  17.   set helpList to [:]
  18.   addProp(helpList, #LogIn, "RCA05HVO")
  19.   addProp(helpList, #menu, "RCA06HVO")
  20.   addProp(helpList, #MakeAscene, "RCA09HVO")
  21.   addProp(helpList, "Sim1", "10HVOR")
  22.   addProp(helpList, "Sim2", "10HVOJ")
  23.   addProp(helpList, "Sim3", "10HVOF")
  24.   addProp(helpList, #VTL, "RCA08HA")
  25.   addProp(helpList, "VTLgame1", "0820HVOR")
  26.   addProp(helpList, "VTLgame2", "0820HVOJ")
  27.   addProp(helpList, "VTLgame3", "0820HVOF")
  28.   addProp(helpList, #JobSite, "RCA07HVO")
  29.   addProp(helpList, #magnifier, "RCA713HV")
  30.   addProp(helpList, #MagNoKeys, "RCA713H2")
  31.   addProp(helpList, #Rotator, "RCA71348")
  32.   addProp(helpList, #QTviewer, "RCA14HVO")
  33.   addProp(helpList, #HardHat, "RCA11HVO")
  34.   addProp(helpList, #Album, "RCA12HVO")
  35.   addProp(helpList, #Culvert, "RCA820HV")
  36.   addProp(helpList, #Ditch, "RCA830HV")
  37.   addProp(helpList, #Dynamite, "RCA1010H")
  38.   addProp(helpList, #Awards, "RCA13HVO")
  39.   return me
  40. end
  41.  
  42. on menuButton me, option
  43.   set currentSection to option
  44.   set section to getAt(sectionList, currentSection)
  45.   unpuppetAll()
  46.   puppetPalette("MainPal", 60)
  47.   go("Grass")
  48.   clearAllActors()
  49.   unLoadCast()
  50.   go(the frame + 1)
  51.   if section = "Simulator" then
  52.     set section to section & string(the level of gLevelObject)
  53.     puppetPalette("SimPal", 60)
  54.     updateStage()
  55.     if the firstTime of gSimObject = 0 then
  56.       if the finishedFlag of gSimObject <> 1 then
  57.         predrawSimButtons(gSimObject)
  58.       end if
  59.     end if
  60.     puppetPalette(0)
  61.   else
  62.     if section = "MakeAscene" then
  63.       puppetPalette("ScenePal", 60)
  64.       updateStage()
  65.       predraw(gSceneObject)
  66.       puppetPalette(0)
  67.     else
  68.       if section = "VTL" then
  69.         if the enabled of gVTLgameObject = 1 then
  70.           set the currentItem of gVTLobject to 1
  71.         end if
  72.         set section to section & string(the currentItem of gVTLobject)
  73.         puppetPalette("VTLpal", 60)
  74.         updateStage()
  75.         predraw(gVTLobject)
  76.         puppetPalette(0)
  77.         go(section)
  78.         cleanUp(me)
  79.         go(the frame + 1)
  80.         repeat while soundBusy(1)
  81.         end repeat
  82.         puppetSound(getAt(the nameSoundList of gVTLobject, the currentItem of gVTLobject))
  83.         moveSign(gVTLobject, #down)
  84.         setup(gVTLobject)
  85.         drawHardHat(gVTLobject)
  86.         repeat while soundBusy(1)
  87.         end repeat
  88.         puppetSound(0)
  89.         flushBuffer()
  90.         abort()
  91.       else
  92.         if section = "3dSite" then
  93.           puppetPalette("JobSitePal", 60)
  94.           updateStage()
  95.           puppetPalette(0)
  96.         end if
  97.       end if
  98.     end if
  99.   end if
  100.   go(section)
  101.   cleanUp(me)
  102.   abort()
  103. end
  104.  
  105. on cleanUp me
  106.   set gRollAnimButton to EMPTY
  107.   set gLoopGroupObject to EMPTY
  108.   clearAllActors()
  109. end
  110.  
  111. on quitButton me, buttonObject
  112.   puppetSprite(the quitButChan of gMenuObject, 1)
  113.   set quitFlag to 1
  114.   set quitButObj to buttonObject
  115.   hideAllActors()
  116.   puppetTransition(51, 1)
  117.   if saveEnabled and gameInProgress(gMenuObject) then
  118.     go("SaveQuit")
  119.     sound playFile 1, gCDpath & "SOUND" & gFileSep & "GLOBAL" & gFileSep & "06VO01G"
  120.   else
  121.     go("WannaQuit")
  122.     sound playFile 1, gCDpath & "SOUND" & gFileSep & "GLOBAL" & gFileSep & "06VO01A"
  123.   end if
  124.   repeat while soundBusy(1)
  125.   end repeat
  126.   puppetSound(0)
  127.   abort()
  128. end
  129.  
  130. on flagButtonHandler me, option
  131.   puppetSound(0)
  132.   set currentSection to option + 4
  133.   set section to getAt(sectionList, currentSection)
  134.   unpuppetAll()
  135.   puppetPalette("MainPal")
  136.   go("Grass")
  137.   clearAllActors()
  138.   unLoadCast()
  139.   go(the frame + 1)
  140.   if section = "Awards" then
  141.     puppetPalette("AwardsPal", 60)
  142.     updateStage()
  143.     predraw(gAwardsObject)
  144.   else
  145.     if section = "HardHat" then
  146.       puppetPalette("HardHatPal", 60)
  147.       updateStage()
  148.       predraw(gHardHatObject)
  149.     else
  150.       if section = "Album" then
  151.         puppetPalette("AlbumPal", 60)
  152.         updateStage()
  153.         predraw(gAlbumObject)
  154.       end if
  155.     end if
  156.   end if
  157.   puppetPalette(0)
  158.   go(section)
  159.   cleanUp(me)
  160.   abort()
  161. end
  162.  
  163. on listSavedGames me
  164.   set savedGameList to [:]
  165.   repeat with gameNum = 1 to 6
  166.     set filePath to gSavePath & "GAME" & string(gameNum)
  167.     set readObject to FileIO(mnew, "read", filePath)
  168.     if not objectp(readObject) then
  169.       set dataString to "empty"
  170.       set writeObject to FileIO(mnew, "write", filePath)
  171.       writeObject(mWriteString, "empty")
  172.       writeObject(mdispose)
  173.     else
  174.       set dataString to readObject(mReadFile)
  175.       readObject(mdispose)
  176.     end if
  177.     set firstItem to item 1 of dataString
  178.     if firstItem <> "RCAgame" then
  179.       addProp(savedGameList, gameNum, "emptySlot")
  180.       next repeat
  181.     end if
  182.     set index to 5
  183.     set nameString to item index of the dataString of gMenuObject
  184.     set letterQuantity to length(nameString)
  185.     set userName to []
  186.     set letterHoffsets to [0]
  187.     repeat with x = 1 to letterQuantity
  188.       add(userName, value(item index + x of dataString))
  189.     end repeat
  190.     repeat with x = 1 to letterQuantity
  191.       add(letterHoffsets, value(item index + letterQuantity + x of dataString))
  192.     end repeat
  193.     addProp(savedGameList, nameString, [userName, letterHoffsets])
  194.   end repeat
  195.   set nonEmptyGames to []
  196.   repeat with x = 1 to count(savedGameList)
  197.     if getAt(savedGameList, x) <> "emptySlot" then
  198.       add(nonEmptyGames, x)
  199.     end if
  200.   end repeat
  201. end
  202.  
  203. on postSavedGames me
  204.   repeat with x = 1 to count(nonEmptyGames)
  205.     set whichGame to getAt(nonEmptyGames, x)
  206.     set gameData to getAt(savedGameList, whichGame)
  207.     set userName to getAt(gameData, 1)
  208.     set letterHoffsets to getAt(gameData, 2)
  209.     set cardCenter to the locH of sprite x
  210.     set nameWidth to getLast(letterHoffsets) + 11
  211.     set locH to cardCenter - integer(nameWidth / 2)
  212.     set locV to the locV of sprite x
  213.     repeat with letterIndex = 1 to count(userName)
  214.       set the castNum of sprite trailsSprite to the firstLetterBmap of gUserObject + getAt(userName, letterIndex) - 1
  215.       set the locH of sprite trailsSprite to locH + getAt(letterHoffsets, letterIndex)
  216.       set the locV of sprite trailsSprite to locV
  217.       updateStage()
  218.     end repeat
  219.   end repeat
  220. end
  221.  
  222. on loadGame me
  223.   if (the clickOn <= count(nonEmptyGames)) and not objectp(gRollAnimButton) then
  224.     puppetAll()
  225.     set the locH of sprite loadGamePopChan to the locH of sprite loadGamePopChan + 1000
  226.     puppetTransition(51, 1)
  227.     go(the frame)
  228.     set whichGame to getAt(nonEmptyGames, the clickOn)
  229.     set the oldUserGameNum of gUserObject to whichGame
  230.     set filePath to gSavePath & "GAME" & string(whichGame)
  231.     set readObject to FileIO(mnew, "read", filePath)
  232.     if not objectp(readObject) then
  233.       alert("Sorry, an error occurred trying to read your saved game.")
  234.       exit
  235.     end if
  236.     set dataString to readObject(mReadFile)
  237.     readObject(mdispose)
  238.     set firstItem to item 1 of dataString
  239.     if firstItem <> "RCAgame" then
  240.       alert("Sorry, that's not a valid Road Construction Ahead game.")
  241.       exit
  242.     end if
  243.     set savedLevel to value(item 2 of dataString)
  244.     set index to 3
  245.     set index to loadUserData(gUserObject, index)
  246.     fillName(gUserObject)
  247.     redrawLevelButtons(gLevelObject, savedLevel)
  248.     updateStage()
  249.     if savedLevel > 1 then
  250.       set the gridSize of gSimObject to "Small"
  251.       initSizeVariables(gSimObject)
  252.       initializeGrid(gSimObject)
  253.     end if
  254.     set index to loadAwards(gAwardsObject, index)
  255.     set index to loadAlbum(gAlbumObject, index)
  256.     set index to loadScene(gSceneObject, index)
  257.     set index to loadHardHats(gHardHatObject, index)
  258.     set index to loadVTLgame(gVTLgameObject, index)
  259.     set index to loadSim(gSimObject, index)
  260.     if the firstTime of gSimObject = 0 then
  261.       set index to loadTruck(gTruckObject, index)
  262.       if savedLevel = 3 then
  263.         set index to loadGasGauge(gGasGaugeObject, index)
  264.         set the firstTime of gGasGaugeObject to 0
  265.       end if
  266.     end if
  267.     set the locH of sprite loadGamePopChan to the locH of sprite loadGamePopChan - 1000
  268.     puppetTransition(51, 1)
  269.     go(the frame)
  270.     playSound("RCA-05VO01")
  271.     set the level of gLevelObject to savedLevel
  272.     set the saveEnabled of gMenuObject to 1
  273.     unLoadCast()
  274.     clearAllActors()
  275.     unpuppetAll()
  276.     drawQuitButton(gMenuObject)
  277.     predraw(gMenuObject)
  278.     drawUserLevel(gUserObject)
  279.     go("LocMap")
  280.     abort()
  281.   end if
  282.   flushBuffer()
  283. end
  284.  
  285. on writeFile me
  286.   if the oldUserGameNum of gUserObject <> 0 then
  287.     set whichGame to the oldUserGameNum of gUserObject
  288.   else
  289.     repeat with whichGame = 1 to count(savedGameList)
  290.       if getAt(savedGameList, whichGame) = "emptySlot" then
  291.         exit repeat
  292.       end if
  293.     end repeat
  294.   end if
  295.   set filePath to gSavePath & "GAME" & string(whichGame)
  296.   set writeObject to FileIO(mnew, "write", filePath)
  297.   if not objectp(writeObject) then
  298.     exit
  299.   end if
  300.   set savedGame to "RCAgame," & string(the level of gLevelObject) & ","
  301.   set savedGame to savedGame & saveUserData(gUserObject)
  302.   set savedGame to savedGame & saveAwardsData(gAwardsObject)
  303.   set savedGame to savedGame & saveAlbum(gAlbumObject)
  304.   set savedGame to savedGame & saveScene(gSceneObject)
  305.   set savedGame to savedGame & saveHardHats(gHardHatObject)
  306.   set savedGame to savedGame & saveVTLgame(gVTLgameObject)
  307.   set savedGame to savedGame & saveSim(gSimObject)
  308.   if the firstTime of gSimObject = 0 then
  309.     set savedGame to savedGame & saveTruck(gTruckObject)
  310.     if the level of gLevelObject = 3 then
  311.       set savedGame to savedGame & saveGasGauge(gGasGaugeObject)
  312.     end if
  313.   end if
  314.   set savedGame to char 1 to length(savedGame) - 1 of savedGame
  315.   writeObject(mWriteString, savedGame)
  316.   writeObject(mdispose)
  317. end
  318.  
  319. on postNamedRoads me
  320.   repeat with x = 1 to count(the namedRoads of gSimObject)
  321.     set whichGame to getAt(nonEmptyGames, x)
  322.     set gameData to getAt(savedGameList, whichGame)
  323.     set userName to getAt(gameData, 1)
  324.     set letterHoffsets to getAt(gameData, 2)
  325.     set locH to the left of sprite x
  326.     set locV to the locV of sprite x
  327.     repeat with letterIndex = 1 to count(userName)
  328.       set the castNum of sprite trailsSprite to the firstLetterBmap of gUserObject + getAt(userName, letterIndex) - 1
  329.       set the locH of sprite trailsSprite to locH + getAt(letterHoffsets, letterIndex)
  330.       set the locV of sprite trailsSprite to locV
  331.       updateStage()
  332.     end repeat
  333.   end repeat
  334. end
  335.  
  336. on setPrefs me, booleanString
  337.   set quitEnabled to value(item 1 of booleanString)
  338.   set saveEnabled to value(item 2 of booleanString)
  339.   set printEnabled to value(item 3 of booleanString)
  340. end
  341.  
  342. on predraw me
  343.   drawUserName(gUserObject, firstNameChan, nameX, nameY)
  344.   addPeriod(gUserObject)
  345. end
  346.  
  347. on help me, buttonObject
  348.   birth(script "Help Parent", buttonObject, #menu)
  349. end
  350.  
  351. on drawQuitButton me
  352.   if quitEnabled = 0 then
  353.     removeSprite(quitButChan)
  354.     puppetSprite(quitButChan, 1)
  355.   end if
  356. end
  357.  
  358. on gameInProgress me
  359.   set flag to 0
  360.   if anyAwards(gAwardsObject) then
  361.     set flag to 1
  362.   end if
  363.   if the firstTime of gSimObject = 0 then
  364.     set flag to 1
  365.   end if
  366.   if the enabled of gVTLgameObject then
  367.     set flag to 1
  368.   end if
  369.   if count(the stickerList of gSceneObject) > 0 then
  370.     set flag to 1
  371.   end if
  372.   return flag
  373. end
  374.